<?php

namespace App\Http\Controllers\Admin\Superadmin;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class EditorController extends Controller
{
	
    /*
		编辑列表页
    */
	public function getIndex()
	{
		// return 'afsgd';
		$edi = DB::table('hs_editor')
		->select('id','e_name')
		->get();

		foreach ($edi as $k => $v) {
			$auth = DB::table('hs_member')
			->join('hs_relation','hs_relation.aid','=','hs_member.id')->where('hs_relation.eid',$v->id)->get();
			$data[$k]['au'] = $auth;
			$data[$k]['ed'] = $v->e_name;
			$data[$k]['id'] = $v->id;
		}
		// dd($data);
		return view('admin.Superadmin.editor.index',['data'=>$data]);
	}

	public function getAdd()
	{
		return view('admin.Superadmin.editor.add');
	}

	public function getEdit($id)
	{
		$ed = DB::table('hs_editor')->where('id',$id)->first();
		// dd($ed);
		return view('admin.superadmin.editor.edit',['ed'=>$ed]);

	}

	public function postUpdate(Request $request)
	{
		$data = $request->except('_token','id');
		$id = $request->input('id');
		// dd($data);
		$res =  DB::table('hs_editor')->where('id',$id)->update($data);
		if($res){
			return redirect('/admin/superadmin/editor/index');
		}else{
			return back();
		}
	}
	

	public function postInsert(Request $request)
	{
		$data = $request->except('_token');
		// dd($data);
		$res =  DB::table('hs_editor')->insert($data);
		if($res){
			return redirect('/admin/superadmin/editor/index');
		}else{
			return back();
		}
	}
		
}		